package com.ada.filter;

import com.ada.IpHolder;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String s = Thread.currentThread().toString();
        //获取到IP
        String ip = IpHolder.threadLocal.get();
        RpcContext.getContext().setAttachment("ip",ip);
        System.out.println("当前线程"+s+"设置ip:"+ ip);
        return invoker.invoke(invocation);
    }
}
